package com.shisfish.library.Controller;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import com.shisfish.library.Impl.BookImpl;
import com.shisfish.library.Impl.BookLendImpl;
import com.shisfish.library.Impl.BookLoanImpl;
import com.shisfish.library.Impl.BookMessageImpl;
import com.shisfish.library.Impl.BookSingleImpl;
import com.shisfish.library.Impl.UserImpl;
import com.shisfish.library.Impl.UserSingleLendImpl;
import com.shisfish.library.Model.Book;
import com.shisfish.library.Model.BookLend;
import com.shisfish.library.Model.BookLoan;
import com.shisfish.library.Model.BookMessage;
import com.shisfish.library.Model.BookSingle;
import com.shisfish.library.Model.User;
import com.shisfish.library.Model.UserLevel;
import com.shisfish.library.Model.UserSingleLend;
import com.shisfish.library.Prere.BeforeBorrow;
import com.shisfish.library.Prere.Login;
import com.shisfish.library.Utils.Global.GlobalVariable;
import com.shisfish.library.Utils.Global.toJsonUtils;
import com.shisfish.library.Utils.PageModel.Page;
import com.shisfish.library.Utils.PageModel.PageUtils;


@Path("bookLend")
public class BookLendController extends GlobalVariable {
	
	private UserSingleLendImpl userSingleLendImpl = new UserSingleLendImpl();
	
	private BookLendImpl bookLendImpl = new BookLendImpl();
	
	private BookSingleImpl bookSingleImpl = new BookSingleImpl();
	
	private BookMessageImpl bookMessageImpl = new BookMessageImpl();
	
	private BookImpl bookImpl = new BookImpl();
	
	private BookLoanImpl bookLoanImpl = new BookLoanImpl();
	
	private UserImpl userImpl = new UserImpl();
	
	/**
	 * @Author shisfish
	 * @Date 2016年1月5日 下午4:36:24
	 * @Descrition : 借书
	 * @param idadmin
	 * @param barCode
	 * @param isbn
	 * @param loanid
	 * @param borrower
	 * @param request
	 * @return
	 */
	@POST
	@Path("lendABook/{idadmin}")
	@Produces("application/json; charset=utf-8")
	public String lendABook(@PathParam("idadmin") String idadmin, @FormParam("barCode") String barCode, 
			@FormParam("isbn") String isbn, @FormParam("loanid") String loanid, @Context HttpServletRequest request) {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		if (Login.isLoginAdmin(idadmin, request)) {
			
			// 通过loanid找用户
			List<User> users = userImpl.selectByLoanid(loanid);
			
			if (users.size() > 0) {
				System.out.println(users.get(0).getEmployee());
				User user = BeforeBorrow.isOverdueOrQuota(users.get(0).getEmployee());
				
				if (user.getEmployee() != null) {
					
					if (user.getUserSingleLend().getBorrow_number() > 0) {
						
						UserSingleLend userSingleLend = user.getUserSingleLend();
							
						Calendar cal = Calendar.getInstance();
						
						// 获得可借书时常
						int borrow_days = user.getUserLevel().getBorrow_days();
						
						cal.add(Calendar.DAY_OF_MONTH, borrow_days);
						
						Date shouldReturnTime = cal.getTime();
						
						BookLend bookLend = new BookLend(barCode, isbn, user.getLoanid(), user.getEmployee(), idadmin, shouldReturnTime, null, 0);
						
						int flag = bookLendImpl.insertOne(bookLend);
						
						if (flag == 1) {
							
							// 借书成功，个人借书信息更改（如果是预约，更改预约信息）
							List<BookLoan> bookLoans = bookLoanImpl.selectByISBNUser(user.getEmployee(), isbn);
							// 有预约， 取消这条预约
							if (bookLoans.size() > 0) {
								
								BookLoan bookLoan = bookLoans.get(0);
								
								bookLoan.setActualCancelTime(new Date());
								
								int flag_4 = bookLoanImpl.updateOne(bookLoan);
								
								if (flag_4 == 1) {
									userSingleLend.setLoaned_number(userSingleLend.getLoaned_number() - 1);
								}
							}
							
							userSingleLend.setBorrowed_number(userSingleLend.getBorrowed_number() + 1);
							
							int flag_1 = userSingleLendImpl.updateOne(userSingleLend);
							
							if (flag_1 == 1) {
								globalMap.put(STATUS_CODE, SUCCESS);
							}
							else {
								globalMap.put(STATUS_CODE, UPDATE_WR);
							}
							
							// 找到那个本barCode
							List<BookSingle> bookSingles = bookSingleImpl.selectBookSM(barCode);
							if (bookSingles.size() > 0) {
								BookSingle bookSingle = bookSingles.get(0);
								bookSingle.setState(2);
								int flag_2 = bookSingleImpl.updateOne(bookSingle);
								
								if (flag_2 == 1) {
									globalMap.put(STATUS_CODE, SUCCESS);
								}
								else {
									globalMap.put(STATUS_CODE, UPDATE_WR);
								}
								
								BookMessage bookMessage = bookSingle.getBookMessage();
								bookMessage.setSurplus(bookMessage.getSurplus() - 1);
								bookMessage.setSurplus_show(bookMessage.getSurplus_show() - 1);
								if (bookMessage.getSurplus_show() == 0) {
									bookMessage.setIsBespeak(1);
								}
								
								int flag_3 = bookMessageImpl.updateOne(bookMessage);
								if (flag_3 == 1) {
									globalMap.put(STATUS_CODE, SUCCESS);
								} else {
									globalMap.put(STATUS_CODE, UPDATE_WR);
								}
							}
							
						}
						else {
							globalMap.put(STATUS_CODE, INSERT_WR);
						}
						
					}
					else {
						// 新增用户借书信息
						// 先查询用户的等级
						// 无预约
						UserLevel userLevel = user.getUserLevel();
						
						UserSingleLend userSingleLend = new UserSingleLend(user.getEmployee(), 0, 0, userLevel.getBorrow_numbers(), userLevel.getLoan_numbers(), user.getLoanid());
						
						int flag = userSingleLendImpl.insertOne(userSingleLend);
						
						if (flag == 1) {
						
							// 未借过书，可借
							
							Calendar cal = Calendar.getInstance();
							
							// 获得可借书时常
							int borrow_days = user.getUserLevel().getBorrow_days();
							
							cal.add(Calendar.DAY_OF_MONTH, borrow_days);
							
							Date shouldReturnTime = cal.getTime();
							
							BookLend bookLend = new BookLend(barCode, isbn, user.getLoanid(), user.getEmployee(), idadmin, shouldReturnTime, null, 0);
							
							int flag_2 = bookLendImpl.insertOne(bookLend);
							
							if (flag_2 == 1) {
								
								// 借书成功，个人借书信息更改
								userSingleLend.setBorrowed_number(userSingleLend.getBorrowed_number() + 1);
								
								int flag_1 = userSingleLendImpl.updateOne(userSingleLend);
								
								if (flag_1 == 1) {
									globalMap.put(STATUS_CODE, SUCCESS);
								}
								else {
									globalMap.put(STATUS_CODE, UPDATE_WR);
								}
								
								// 找到那个本barCode
								List<BookSingle> bookSingles = bookSingleImpl.selectBookSM(barCode);
								if (bookSingles.size() > 0) {
									BookSingle bookSingle = bookSingles.get(0);
									bookSingle.setState(2);
									int flag_3 = bookSingleImpl.updateOne(bookSingle);
									
									if (flag_3 == 1) {
										globalMap.put(STATUS_CODE, SUCCESS);
									}
									else {
										globalMap.put(STATUS_CODE, UPDATE_WR);
									}
									
									BookMessage bookMessage = bookSingle.getBookMessage();
									bookMessage.setSurplus(bookMessage.getSurplus() - 1);
									bookMessage.setSurplus_show(bookMessage.getSurplus_show() - 1);
									if (bookMessage.getSurplus_show() == 0) {
										bookMessage.setIsBespeak(1);
									}
									
									int flag_4 = bookMessageImpl.updateOne(bookMessage);
									if (flag_4 == 1) {
										globalMap.put(STATUS_CODE, SUCCESS);
									} else {
										globalMap.put(STATUS_CODE, UPDATE_WR);
									}
								}
								
							}
							
						}
						else {
							globalMap.put(STATUS_CODE, INSERT_WR);
						}
					}
					
				} else {
					globalMap.put(STATUS_CODE, OVERDUE_QUOTA);
				}
			} else {
				globalMap.put(STATUS_CODE, SELECT_EMPTY);
			}
		}
		else {
			globalMap.put(STATUS_CODE, NOT_LOGGED_IN);
		}
		
		return toJsonUtils.map2Json(globalMap);
	}
	
	/**
	 * @Author shisfish
	 * @Date 2016年1月5日 下午4:39:49
	 * @Descrition : 过期
	 * @return
	 */
	@GET
	@Path("overRecord")
	@Produces("application/json; charset=utf-8")
	public String OverRecord() {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		List<BookLend> bookLends = new BookLendImpl().selectOverdue();
		
		if (bookLends.size() > 0) {
			System.out.println("ok");
			
			// 找到全部的过期用户对象
			Set<String> borrowers = new HashSet<String>();
			for (int i = 1, len = bookLends.size(); i < len; i++) {
				borrowers.add(bookLends.get(i).getBorrower());
			}
			
			// 单个用户一条数据
			List<HashMap<String, Object>> overdue = new ArrayList<HashMap<String, Object>>();
			for (String string : borrowers) {
				List<Book> books = new ArrayList<Book>();
				List<BookSingle> bookSingles = new ArrayList<BookSingle>();
				for (int i = 0, len = bookLends.size(); i < len; i++) {
					if (bookLends.get(i).getBorrower().equals(string)) {
						books.add(bookLends.get(i).getBook());
						bookSingles.add(bookLends.get(i).getBookSingle());
					}
				}
				HashMap<String, Object> temp = new HashMap<String, Object>();
				temp.put("borrowers", string);
				temp.put("books", books);
				temp.put("bookSingles", bookSingles);
				overdue.add(temp);
			}
			
			// 把用户信息添加进去
			for (HashMap<String, Object> hashMap : overdue) {
				for (int i = 0, len = bookLends.size(); i < len; i++) {
					User user = bookLends.get(i).getUser();
					if (hashMap.get("borrowers").equals(user.getEmployee())) {
						hashMap.put("users", user);
						break;
					}
				}
			}
			globalMap.put("list", overdue);
			
		}
		else {
			System.out.println("wrong");
		}
		
		return toJsonUtils.map2Json(globalMap);
		
	}
	
	/**
	 * @Author shisfish
	 * @Date 2016年1月5日 下午4:40:21
	 * @Descrition : 过期
	 * @param idadmin
	 * @param barCode
	 * @param isbn
	 * @param loanid
	 * @param borrower
	 * @param request
	 * @return
	 */
	@POST
	@Path("insertOne/{idadmin}")
	@Produces("application/json; charset=utf-8")
	public String insertOne(@PathParam("idadmin") String idadmin, @FormParam("barCode") String barCode, 
			@FormParam("isbn") String isbn, @FormParam("loanid") String loanid, 
			@FormParam("borrower") String borrower, @Context HttpServletRequest request) {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		BookLend bookLend = new BookLend(barCode, isbn, loanid, borrower, idadmin, null, null, 0);
		
		int flag = bookLendImpl.insertOne(bookLend);
		
		if (flag == 1) {
			System.out.println("success");
		} else {
			System.out.println("error");
		}
		
		return toJsonUtils.map2Json(globalMap);
		
	}
	
	/**
	 * @Author shisfish
	 * @Date 2016年1月5日 下午4:40:37
	 * @Descrition : 归还书
	 * @param idadmin
	 * @param barCode
	 * @param request
	 * @return
	 */
	@POST
	@Path("returnABook/{idadmin}")
	@Produces("application/json; charset=utf-8")
	public String returnABook(@PathParam("idadmin") String idadmin, @FormParam("barCode") String barCode, 
			@Context HttpServletRequest request) {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		
		if (Login.isLoginAdmin(idadmin, request)) {
			
			// 找到这本书，改变数的状态
			List<BookSingle> bookSingles = bookSingleImpl.selectBookSM(barCode);
			
			if (bookSingles.size() > 0) {
				BookSingle bookSingle = bookSingles.get(0);
				bookSingle.setState(0);
				
				int flag = bookSingleImpl.updateOne(bookSingle);
				if (flag == 1) {
					globalMap.put(STATUS_CODE, SUCCESS);
				} else {
					globalMap.put(STATUS_CODE, UPDATE_WR);
				}
				
				//图书数量信息改变
				BookMessage bookMessage = bookSingle.getBookMessage();
				
				// 如果有人预约
				if (bookMessage.getNumber() > 0) {
					bookMessage.setSurplus(bookMessage.getSurplus() + 1);
				} else {
					bookMessage.setSurplus(bookMessage.getSurplus() + 1);
					bookMessage.setSurplus_show(bookMessage.getSurplus_show() + 1);
					bookMessage.setIsBespeak(0);
				}
				int flag_1 = bookMessageImpl.updateOne(bookMessage);
				if (flag_1 == 1) {
					globalMap.put(STATUS_CODE, SUCCESS);
				} else {
					globalMap.put(STATUS_CODE, UPDATE_WR);
				}
				
				// 借书记录的改变
				List<BookLend> bookLends = bookLendImpl.selectByKey(barCode);
				
				if (bookLends.size() > 0) {
					BookLend bookLend = bookLends.get(0);
					bookLend.setActualReturnTime(new Date());
					bookLend.setLendStatus(1);
					
					int flag_2 = bookLendImpl.updateOne(bookLend);
					
					if (flag_2 == 1) {
						globalMap.put(STATUS_CODE, SUCCESS);
					} else {
						globalMap.put(STATUS_CODE, UPDATE_WR);
					}
					
					// 用户借书的数据改变
					List<UserSingleLend> userSingleLends = userSingleLendImpl.selectByKey(bookLend.getBorrower());
					
					if (userSingleLends.size() > 0) {
						
						UserSingleLend userSingleLend = userSingleLends.get(0);
						userSingleLend.setBorrowed_number(userSingleLend.getBorrowed_number() - 1);
						int flag_3 = userSingleLendImpl.updateOne(userSingleLend);
						if (flag_3 == 1) {
							globalMap.put(STATUS_CODE, SUCCESS);
						} else {
							globalMap.put(STATUS_CODE, UPDATE_WR);
						}
						
					} else if (userSingleLends.size() == 0) {
						globalMap.put(STATUS_CODE, SELECT_EMPTY);
					} else {
						globalMap.put(STATUS_CODE, SELECT_WR);
					}
					
				} else if (bookLends.size() == 0) {
					globalMap.put(STATUS_CODE, SELECT_EMPTY);
				} else {
					globalMap.put(STATUS_CODE, SELECT_WR);
				}
			} else if (bookSingles.size() == 0) {
				globalMap.put(STATUS_CODE, SELECT_EMPTY);
			} else {
				globalMap.put(STATUS_CODE, SELECT_WR);
			}
			
		}
		else {
			globalMap.put(STATUS_CODE, NOT_LOGGED_IN);
		}
		
		return toJsonUtils.map2Json(globalMap);
	}
	
	/**
	 * @Author shisfish
	 * @Date 2016年1月5日 下午4:41:55
	 * @Descrition : 查询所有的借书信息
	 * @return
	 */
	@GET
	@Path("selectAll")
	@Produces("application/json; charset=utf-8")
	public String selectAll() {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		
		List<BookLend> bookLends = bookLendImpl.selectAll();
		
		if (bookLends.size() > 0) {
			globalMap.put("list", bookLends);
			globalMap.put(STATUS_CODE, SUCCESS);
		} else if (bookLends.size() == 0) {
			globalMap.put(STATUS_CODE, SELECT_EMPTY);
		} else {
			globalMap.put(STATUS_CODE, SELECT_WR);
		}
		
		return toJsonUtils.map2Json(globalMap);
	}
	
	/**
	 * @Author shisfish
	 * @Date 2016年1月5日 下午4:42:23
	 * @Descrition : 借书信息（分页）
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@GET
	@Path("lendMessage/{currentPage}/{pageSize}")
	@Produces("application/json; charset=utf-8")
	public String lendMessage(@PathParam("currentPage") int currentPage, @PathParam("pageSize") int pageSize) {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		
		int count = bookLendImpl.countAll();
		
		if (count > 0) {
			Page page = PageUtils.createPage(count, currentPage, pageSize);
			
			List<Map<String, Object>> test = bookLendImpl.selectAllMessage1(page.getBeginIndex(), pageSize);
			
			if (test.size() > 0) {
				globalMap.put("list", test);
				globalMap.put(STATUS_CODE, SUCCESS);
			} else if (test.size() == 0) {
				globalMap.put(STATUS_CODE, SELECT_EMPTY);
			} else {
				globalMap.put(STATUS_CODE, SELECT_WR);
			}
		} else if (count == 0) {
			globalMap.put(STATUS_CODE, SELECT_EMPTY);
		} else {
			globalMap.put(STATUS_CODE, SELECT_WR);
		}
		return toJsonUtils.map2Json(globalMap);
	}
	
	/**
	 * @Author shisfish
	 * @Date 2015年12月31日 下午3:58:17
	 * @Descrition : 查找被借次数最多的书（10本）
	 * @return
	 */
	@GET
	@Path("maxBorrowed")
	@Produces("application/json; charset=utf-8")
	public String maxBorrowed() {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		
		List<Map<String, Object>> books = bookLendImpl.maxBorrowed();
		
		if (books.size() >= 0) {
			if (books.size() == 10) {
				globalMap.put("list", books);
				globalMap.put(STATUS_CODE, SUCCESS);
			} else {
				int count = 10 - books.size();
				// 随便找几本书代替
				List<Map<String, Object>> otherbooks = bookImpl.selectOtherBooks(count);
				books.addAll(otherbooks);
				
				globalMap.put("list", books);
				globalMap.put(STATUS_CODE, SUCCESS);
			}
		}
		else {
			globalMap.put(STATUS_CODE, SELECT_ERROR);
		}
		
		return toJsonUtils.map2Json(globalMap);
		
	}
	
	/**
	 * @Author shisfish
	 * @Date 2016年1月7日 下午4:29:25
	 * @Descrition : 查询某天借书记录（分页）
	 * @param idadmin
	 * @param choDate
	 * @param request
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@POST
	@Path("selectByDate/{idadmin}/{currentPage}/{pageSize}")
	@Produces("application/json; charset=utf-8")
	public String selectByDate(@PathParam("idadmin") String idadmin, @FormParam("choDate") String choDate, 
			@Context HttpServletRequest request, 
			@PathParam("currentPage") int currentPage, @PathParam("pageSize") int pageSize) {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		if (Login.isLoginAdmin(idadmin, request)) {
			
			int count = bookLendImpl.countByDate(choDate);
			
			if (count > 0) {
				
				Page page = PageUtils.createPage(count, currentPage, pageSize);
				List<Map<String, Object>> bookLends = bookLendImpl.selectByDate(choDate, page.getBeginIndex(), pageSize);
				
				if (bookLends.size() > 0) {
					globalMap.put("list", bookLends);
					globalMap.put("page", page);
					globalMap.put(STATUS_CODE, SUCCESS);
				} else if (bookLends.size() == 0) {
					globalMap.put(STATUS_CODE, SELECT_EMPTY);
				} else {
					globalMap.put(STATUS_CODE, SELECT_WR);
				}
			} else if (count == 0) {
				globalMap.put(STATUS_CODE, SELECT_EMPTY);
			} else {
				globalMap.put(STATUS_CODE, SELECT_WR);
			}
		} else {
			globalMap.put(STATUS_CODE, NOT_LOGGED_IN);
		}
		
		return toJsonUtils.map2Json(globalMap);
		
	}
	
	/**
	 * @Author shisfish
	 * @Date 2016年1月7日 下午4:29:57
	 * @Descrition : 查询某天借书记录（按借书者排序）（分页）
	 * @param idadmin
	 * @param choDate
	 * @param request
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@POST
	@Path("adderLogByDate/{idadmin}/{currentPage}/{pageSize}")
	@Produces("application/json; charset=utf-8")
	public String adderLogByDate(@PathParam("idadmin") String idadmin, @FormParam("choDate") String choDate, 
			@Context HttpServletRequest request, 
			@PathParam("currentPage") int currentPage, @PathParam("pageSize") int pageSize) {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		if (Login.isLoginAdmin(idadmin, request)) {
			
			int count = bookLendImpl.countLendLogByDate(choDate);
			
			if (count > 0) {
				Page page = PageUtils.createPage(count, currentPage, pageSize);
				List<Map<String, Object>> bookLends = bookLendImpl.lendLogByDate(choDate, page.getBeginIndex(), pageSize);
				
				if (bookLends.size() > 0) {
					globalMap.put("list", bookLends);
					globalMap.put("page", page);
					globalMap.put(STATUS_CODE, SUCCESS);
				} else if (bookLends.size() == 0) {
					globalMap.put(STATUS_CODE, SELECT_EMPTY);
				} else {
					globalMap.put(STATUS_CODE, SELECT_WR);
				}
			} else if (count == 0) {
				globalMap.put(STATUS_CODE, SELECT_EMPTY);
			} else {
				globalMap.put(STATUS_CODE, SELECT_WR);
			}
			
		} else {
			globalMap.put(STATUS_CODE, NOT_LOGGED_IN);
		}
		
		return toJsonUtils.map2Json(globalMap);
		
	}

	/**
	 * @Author shisfish
	 * @Date 2016年1月7日 下午4:30:23
	 * @Descrition : 通过借书者id查询某天借书记录（分页）
	 * @param idadmin
	 * @param userId
	 * @param choDate
	 * @param request
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@POST
	@Path("adderLogByDateAdder/{idadmin}/{currentPage}/{pageSize}")
	@Produces("application/json; charset=utf-8")
	public String adderLogByDateAdder(@PathParam("idadmin") String idadmin, @FormParam("userId") String userId, 
			@FormParam("choDate") String choDate, @Context HttpServletRequest request, 
			@PathParam("currentPage") int currentPage, @PathParam("pageSize") int pageSize) {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		
		if (Login.isLoginAdmin(idadmin, request)) {
			
			int count = bookLendImpl.countLendLogByDateBorrower(userId, choDate);
			
			if (count > 0) {
				Page page = PageUtils.createPage(count, currentPage, pageSize);
				List<Map<String, Object>> bookLends = bookLendImpl.lendLogByDateBorrower(userId, choDate, page.getBeginIndex(), pageSize);
				if (bookLends.size() > 0) {
					globalMap.put("list", bookLends);
					globalMap.put("page", page);
					globalMap.put(STATUS_CODE, SUCCESS);
				} else if (bookLends.size() == 0) {
					globalMap.put(STATUS_CODE, SELECT_EMPTY);
				} else {
					globalMap.put(STATUS_CODE, SELECT_WR);
				}
			} else if (count == 0) {
				globalMap.put(STATUS_CODE, SELECT_EMPTY);
			} else {
				globalMap.put(STATUS_CODE, SELECT_WR);
			}
			
		} else {
			globalMap.put(STATUS_CODE, NOT_LOGGED_IN);
		}
		
		return toJsonUtils.map2Json(globalMap);
		
	}
	
	/**
	 * @Author shisfish
	 * @Date 2016年1月14日 下午4:33:45
	 * @Descrition : 单本书的借阅历史记录（分页）
	 * @param isbn
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@GET
	@Path("bookLendLog/{isbn}/{currentPage}/{pageSize}")
	@Produces("application/json; charset=utf-8")
	public String bookLendLog(@PathParam("isbn") String isbn, @PathParam("currentPage") int currentPage, @PathParam("pageSize") int pageSize) {
		Map<String, Object> globalMap = new HashMap<String, Object>();
		
		int count = bookLendImpl.bookLogCount(isbn);
		
		if (count > 0) {
			Page page = PageUtils.createPage(count, currentPage, pageSize);
			List<Map<String, Object>> log = bookLendImpl.bookLogPage(isbn, page.getBeginIndex(), pageSize);
			
			if (log.size() > 0) {
				globalMap.put(STATUS_CODE, SUCCESS);
				globalMap.put("page", page);
				globalMap.put("list", log);
			} else if (log.size() == 0) {
				globalMap.put(STATUS_CODE, SELECT_EMPTY);
			} else {
				globalMap.put(STATUS_CODE, SELECT_WR);
			}
		} else if (count == 0) {
			globalMap.put(STATUS_CODE, SELECT_EMPTY);
		} else {
			globalMap.put(STATUS_CODE, SELECT_WR);
		}
		return toJsonUtils.map2Json(globalMap);
	}
	
	
}
